package com.xiaoshuidi.cloud.module.rooms.controller.admin.pricing;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.pricing.vo.*;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomPricingService;
import com.xiaoshuidi.cloud.module.rooms.service.RoomLayoutService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 定价相关接口
 *
 * @Author Feng
 * @date 2023/5/15
 */
@Tag(name = "管理后台 - 定价定价相关")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping(ApiConstants.NAME + "/pricing")
public class RoomPricingController {

    private final RoomLayoutService roomLayoutService;
    private final IRoomPricingService roomPricingService;

    /**
     * 房型定价分页
     *
     * @return
     */
    @Operation(summary = "房型定价分页")
    @GetMapping("/layout/page")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:query')")
    public CommonResult<PageResult<LayoutPricingPageResp>> layoutRicingPage(@Valid LayoutPricingPageReq req) {
        return CommonResult.success(roomLayoutService.pricingLayoutPage(req));
    }


    /**
     * 调整房型价格
     *
     * @param req
     * @return
     */
    @Operation(summary = "调整房型价格")
    @PostMapping("/set/layout/pricing")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:set-layout')")
    public CommonResult<Boolean> setLayoutPricing(@RequestBody @Valid SetLayoutPricingReq req) {
        return CommonResult.success(roomPricingService.setLayoutPricing(req));
    }

    /**
     * 集中式/分散式房间定价列表
     *
     * @param req
     * @return
     */
    @Operation(summary = "集中式/分散式房间定价列表")
    @GetMapping("/house/page")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:house-query')")
    public CommonResult<PageResult<RoomHousePricingPageResp>> roomHousePricingPage(@Valid RoomHouseRicingPageReq req) {
        return CommonResult.success(roomPricingService.roomHousePricingPage(req));
    }

    /**
     * 分散式房源/集中式房间定价
     *
     * @param req
     * @return
     */
    @Operation(summary = "分散式房源/集中式房间定价")
    @PostMapping("/set/house/pricing")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:set-house')")
    public CommonResult<Boolean> setHousePricing(@RequestBody @Valid SetHousePricingReq req) {
        return CommonResult.success(roomPricingService.setHousePricing(req));
    }

    /**
     * 空间定价列表
     *
     * @param req
     * @return
     */
    @Operation(summary = "空间定价列表")
    @GetMapping("/rental/space/page")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:space-query')")
    public CommonResult<PageResult<RentalSpacePricingPageResp>> rentalSpacePricingPage(@Valid RentalSpacePricingPageReq req) {
        return CommonResult.success(roomPricingService.rentalSpacePricingPage(req));
    }

    /**
     * 设置空间定价
     *
     * @param req
     * @return
     */
    @Operation(summary = "设置空间定价")
    @PostMapping("/set/rental/space/pricing")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:set-space')")
    public CommonResult<Boolean> setRentalSpacePricing(@RequestBody @Valid SetRentalSpacePricingReq req) {
        return CommonResult.success(roomPricingService.setRentalSpacePricing(req));
    }

    /**
     * 房源定价导出
     *
     * @param req
     * @return
     */
    @Operation(summary = "房源定价导出")
    @PostMapping("/house/pricing/export")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:house-export')")
    public CommonResult<HousePricingExportResp> housePricingExport(@RequestBody @Valid HousePricingExportReq req) {
        return CommonResult.success(roomPricingService.housePricingExport(req));
    }

    /**
     * 房源定价模板导出
     *
     * @param req
     * @return
     */
    @Operation(summary = "房源定价模板导出")
    @PostMapping("/house/pricing/template/export")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:house-template-export')")
    public CommonResult<HousePricingExportResp> housePricingTemplateExport(@RequestBody @Valid HousePricingExportReq req) {
        return CommonResult.success(roomPricingService.housePricingTemplateExport(req));
    }

    /**
     * 空间定价导出
     *
     * @param req
     * @return
     */
    @Operation(summary = "空间定价导出")
    @PostMapping("/space/pricing/export")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:space-export')")
    public CommonResult<String> spacePricingExport(@RequestBody @Valid RentalSpacePricingExportReq req) {
        return CommonResult.success(roomPricingService.spacePricingExport(req));
    }

    /**
     * 房源定价-导入
     *
     * @param req
     * @return
     */
    @Operation(summary = "房源定价-导入")
    @PostMapping("/house/pricing/import")
//    @PreAuthorize("@ss.hasAnyPermissions('rooms:pricing:house-import')")
    public CommonResult<Boolean> housePricingImport(@RequestBody @Valid HousePricingImportReq req) {
        return CommonResult.success(roomPricingService.housePricingImport(req.getApartmentId(), req.getIsConcentrated(), req.getFileUrl()));
    }
}
